#ifndef _TANKMESSAGE_H_
#define _TANKMESSAGE_H_

enum {
	MOVE_MODE_PWM = 0,
	MOVE_MODE_PID = 1,
};

typedef nx_struct tank_move_msg {
	nxle_uint16_t seqnum;
	nxle_uint8_t mode;
	nxle_int16_t vleft;
	nxle_int16_t vright;
	nxle_uint16_t time;
} tank_move_msg_t;

typedef nx_struct tank_pid_settings_msg {
	nxle_uint16_t seqnum;
	nxle_int16_t Cp;
	nxle_int16_t Ci;
	nxle_uint16_t dt;
} tank_pid_settings_msg_t;

typedef nx_struct tank_servo_msg {
	nxle_uint16_t seqnum;
	nxle_uint16_t servo1;	
	nxle_uint16_t servo2;	
	nxle_uint16_t servo3;	
} tank_servo_msg_t;

typedef nx_struct tank_power_msg {
	nxle_uint16_t seqnum;
	nxle_uint16_t power;	
} tank_power_msg_t;

typedef nx_struct tank_tower_msg {
	nxle_uint16_t seqnum;
	nxle_uint8_t cmd;
	nx_union {

		nx_struct {
			nxle_int8_t speed;
		} s_center;

		nx_struct {
			nxle_int8_t speed;
			nxle_uint16_t time;
		} s_t;
		
		nx_struct {
			nxle_int8_t speed;
			nxle_int16_t position;
		} s_pos;
		
		nx_struct {
			nxle_int8_t speed;
			nxle_int16_t relposition;
		} s_relpos;
	} params;
} tank_tower_msg_t;

// Az elozo felepitese: (1 byte parancs, 0-3 byte parameter) *
// Parancsok:
	enum {
		CMD_NONE = 0,
		CMD_TURN_CENTER = 1,  // speed (-127..127)
		CMD_TURN_SPEED_TIME = 2,      // speed (-127..127) and time (0..65535 ms)
		CMD_TURN_SPEED_POS = 3,     // speed (-127..127) and position (int16_t)
		CMD_TURN_SPEED_RELPOS = 4,  // speed (-127..127) and relative position (int16_t)
		IDLE,
		ERROR
	};


typedef nx_struct tank_response_msg {
	nxle_uint16_t seqnum;

	nxle_uint8_t state;
	// TODO

} tank_response_msg_t;

typedef nx_struct tank_debug_pid_msg {
	nxle_uint16_t csleft;
	nxle_uint16_t csright;
	nxle_int16_t Ileft;
	nxle_int16_t Iright;
	nxle_int16_t pwmleft;
	nxle_int16_t pwmright;
} tank_debug_pid_msg_t;


enum {
	AM_TANK_MOVE_MSG = 10,
	AM_TANK_POWER_MSG = 11,
	AM_TANK_TOWER_MSG = 12,
	AM_TANK_SERVO_MSG = 13,
	AM_TANK_PID_SETTINGS_MSG = 14,

	AM_TANK_DEBUG_PID_MSG = 16,
	
	AM_TANK_RESPONSE_MSG = 15,
};

#endif
